package ru.urfc.portal.ui.client.renderers;

import java.util.Date;

import ru.urfc.portal.ui.client.Utils;
import ru.urfc.portal.ui.client.descriptor.CompositeGridField;
import ru.urfc.portal.ui.client.descriptor.GridField;

import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.dom.client.Element;

public class ContractRenderer extends SimpleRenderer {
	
	CompositeGridField compositeGridField;
	
	public ContractRenderer(CompositeGridField compositeGridField, Element element) {
		super(compositeGridField, element);
		this.compositeGridField = compositeGridField;
	}

	@Override
	public String render(ModelData modelData) {
		GridField numberField = compositeGridField.getGridFields().get(0);
		GridField issueDateField = compositeGridField.getGridFields().get(1);
		GridField expireDateField = compositeGridField.getGridFields().get(2);
		String number = numberField.getValue(modelData);
		Date issueDate = issueDateField.getValue(modelData);
		Date expireDate = expireDateField.getValue(modelData);
		if (number == null || issueDateField == null) {
			return "";
		}
		return "Договор №" + number + " от " + Utils.dateToStr(issueDate) + " \"Об оказании услуг\"" +
			 (expireDate == null? ", бессрочный": ", действует до " + Utils.dateToStr(expireDate));
	}
}
